home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / fp.c < prev    next >
Text File  |  1995-08-15  |  3KB  |  119 lines

  1. /* fp.c
  2. NOTE: as of System 7.5.1 Apple's fp routines are available on both
  3. PowerPC and 68k Macs, so this file is obsolete.
  4.  
  5. Apple provides a whole bunch of nice functions that are defined in fp.h, but
  6. unfortunately, at present they only exist on the PowerPC. As a stop-gap, until
  7. Apple provides them for 68k machines as well, I've written these 68k-compatible
  8. equivalents. You can safely include this file in all your projects. This file
  9. omits itself if Apple's versions of the functions are available.
  10.  
  11. At present this file only defines: ldtox80, x80told, and fpclassify. This replaces
  12. the functions formerly provided by the VideoToolbox Sane.c, which I've now discarded.
  13. You may also want to look at the functions defined in IsNan.c, which are very
  14. similar, though not identical to several fp.h functions.
  15.  
  16. ldtox80 and x80told convert back and forth between long double (any size)
  17. and 10-byte floating point formats. The 10- and 12-byte formats contain exactly
  18. the same information. The 12-byte format, used by the Motorola 68881 and 68040
  19. floating point chips, has an unused 2-byte gap between the exponent and mantissa.
  20.  
  21. KNOWN BUGS:
  22. Bosco Tjan reported that Symantec C++ doesn't like this file, as noted below. I'm not
  23. bothering to fix it because as far as I know this file is obsolete. If I'm
  24. wrong, and you need to use this file, let me know and I'll try to fix it.
  25.  
  26. Undefined "x96tox80,x80tox96,extended80,extended96".  
  27. When I changed the code from #if 0 to #if 1 to include SANE.h,
  28. I still got one problem -- extended96 is not defined on PPCs"
  29.  
  30.  
  31. HISTORY:
  32. 10/8/94 dgp wrote it.
  33. */
  34. #include "VideoToolbox.h"
  35. #if !defined(__FP__)    // Conditional applies to rest of file.
  36.  
  37. #if 0
  38.     #undef INF
  39.     #undef PI
  40.     #undef NAN
  41.     #include <SANE.h>    // x96tox80,x80tox96,extended80,extended96
  42. #else
  43.     // if extended80 and extended96 are undefined, change the "#if 0" to "#if 1" above.
  44.     void x96tox80(extended96 *,extended80 *);
  45.     void x80tox96(extended80 *,extended96 *);
  46. #endif
  47. #include <assert.h>
  48. void ldtox80 (long double *xl,extended80 *x80);
  49. void x80told (extended80 *x80,long double *xl);
  50. long int fpclassify(double x);
  51.  
  52. void ldtox80 (long double *xl,extended80 *x80)
  53. {
  54.     double x;
  55.     
  56.     switch(sizeof(long double)){
  57.     case 12:
  58.         x96tox80((extended96 *)xl,x80);
  59.         return;
  60.     case 10:
  61.         *x80=*(extended80 *)xl;
  62.         return;
  63.     default:
  64.         switch(sizeof(double)){
  65.         case 12:
  66.             x=*xl;
  67.             x96tox80((extended96 *)&x,x80);
  68.             break;
  69.         case 10:
  70.             *(double *)x80=*xl;
  71.             break;
  72.         default:
  73.             assert(0);
  74.         }
  75.     }
  76. }
  77.  
  78. void x80told (extended80 *x80,long double *xl)
  79. {
  80.     double x;
  81.  
  82.     switch(sizeof(long double)){
  83.     case 12:
  84.         x80tox96(x80,(extended96 *)xl);
  85.         break;
  86.     case 10:
  87.         *xl=*(long double *)x80;
  88.         break;
  89.     default:
  90.         switch(sizeof(double)){
  91.         case 12:
  92.             x80tox96(x80,(extended96 *)&x);
  93.             *xl=x;
  94.             break;
  95.         case 10:
  96.             *xl=*(double *)x80;
  97.             break;
  98.         default:
  99.             assert(0);
  100.         }
  101.     }
  102. }
  103.  
  104. pascal void MyClassExtended(extended80 *,short *) = { 0x3F3C,0x001C,0xA9EB };
  105.  
  106. long int fpclassify(double x)
  107. {
  108.     short n;
  109.     extended80 x80;
  110.     long double xl;
  111.  
  112.     xl=x;
  113.     ldtox80(&xl,&x80);
  114.     MyClassExtended(&x80,&n);
  115.     return n;
  116. }
  117.  
  118. #endif
  119.